import http from '@/utils/http';

/**
 * 获取入库单列表
 * @param {Object} params - 查询参数
 */
export function getInboundList(params) {
  return http.get('/inventory/inbound/orders', { params });
}

/**
 * 获取入库统计数据
 * @returns {Promise} 返回统计数据的Promise对象
 */
export function getInboundStatisticsData() {
  return http.get('/inventory/inbound/statistics');
}

/**
 * 获取入库单详情
 * @param {Number|String} id - 入库单ID
 */
export function getInboundDetail(id) {
  return http.get(`/inventory/inbound/orders/${id}`);
}

/**
 * 创建入库单
 * @param {Object} data - 入库单信息
 */
export function createInbound(data) {
  return http.post('/inventory/inbound/orders', data);
}

/**
 * 更新入库单
 * @param {Number|String} id - 入库单ID
 * @param {Object} data - 更新的入库单信息
 */
export function updateInbound(id, data) {
  return http.put(`/inventory/inbound/orders/${id}`, data);
}

/**
 * 删除入库单
 * @param {Number|String} id - 入库单ID
 */
export function deleteInbound(id) {
  return http.delete(`/inventory/inbound/orders/${id}`);
}

/**
 * 更改入库单状态
 * @param {Number|String} id - 入库单ID
 * @param {String} status - 新状态
 */
export function updateInboundStatus(id, status) {
  return http.put(`/inventory/inbound/orders/${id}/status`, { status });
}

/**
 * 执行收货操作
 * @param {Number|String} id - 入库单ID
 * @param {Object} data - 收货数据
 */
export function receiveInbound(id, data) {
  return http.post(`/inventory/inbound/orders/${id}/receive`, data);
}

/**
 * 执行上架操作
 * @param {Number|String} id - 入库单ID
 * @param {Object} data - 上架数据
 */
export function putawayInbound(id, data) {
  return http.post(`/inventory/inbound/orders/${id}/putaway`, data).then(response => {
    if (response.message === 'success') {
      response.message = '上架成功';
    }
    return response;
  });
}

/**
 * 获取待处理收货任务
 */
export function getReceivingTasks() {
  return http.get('/inventory/inbound/tasks/receiving');
}

/**
 * 获取待处理上架任务
 */
export function getPutawayTasks() {
  return http.get('/inventory/inbound/tasks/putaway');
}

/**
 * 取消入库单
 * @param {Number|String} id - 入库单ID
 */
export function cancelInbound(id) {
  return http.post(`/inventory/inbound/orders/${id}/cancel`, {});
}

export default {
  getInboundList,
  getInboundDetail,
  createInbound,
  updateInbound,
  deleteInbound,
  updateInboundStatus,
  receiveInbound,
  putawayInbound,
  getReceivingTasks,
  getPutawayTasks,
  cancelInbound,
  getInboundStatisticsData,
  inboundStatisticsData: getInboundStatisticsData
}; 